﻿<div class="padding5">
    <div>
        <table id="configList" style="height: auto; min-height: 240px;" class="" title="第三方巡检维护" pagination="true" url="/PlanManagement/GetThirdPartyInspection"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="ID" width="140" sortable="true">编号</th>
                    <th field="Name" width="140" sortable="true">第三方巡检类型</th>
                    <th field="CreateTime" formatter="DateFormate" width="100" sortable="true">添加时间</th>
                    <th field="CreatorName" width="100" sortable="true">添加人</th>
                    <th field="Ope" width="60">操作</th>
                </tr>
            </thead>
        </table>
    </div>
    <div class="padding20">
        第三方巡检类型：<input type="text" id="configType" />
        <input type="button" value="添加" onclick="addConfig();" />
        <input type="button" value="取消" onclick="cancelConfig();" />
    </div>

</div>
<script type="text/javascript">
    var addConfig = function () {
        if ($('#configType').val()) {
            var data = {};
            data["Name"] = $.trim($('#configType').val());

            $.post('/PlanManagement/CreateInsType', data, function (res) {
                if (res == "OK") {
                    $('#configList').datagrid('reload');
                    $('#configType').val('');
                }
                if (res == "Error") {
                    $.messager.alert('错误', '保存失败!', 'error');
                }
            });
        }
    };

    var cancelConfig = function () {
        $('#configType').val('');
    };

    $(function () {
        $.fn.datagrid.defaults.view.onBeforeRender = function (target, rows) {
            $.each(rows, function (i, val) {
                val["Ope"] = '<a class="deleteRow">删除</a>';
            });
        };

        $('#configList').datagrid({
            pageList: [5],
            pageSize: 5,
            pageNumber: 1,
            onClickCell: function (rowIndex, field, value) {
                if (field == "Ope") {
                    $.post('/PlanManagement/DeleteInsType', {
                        ID: $('#configList').datagrid('getData').rows[rowIndex]["ID"]
                    }, function (res) {
                        if (res == "OK") {
                            $('#configList').datagrid('reload');
                        }
                        if (res == "Error") {
                            $.messager.alert('错误', '删除失败!', 'error');
                        }
                    });
                    $('#configList').datagrid('deleteRow', rowIndex);
                }
            }
        });

        var p2 = $('#configList').datagrid('getPager');
        $(p2).pagination({
            beforePageText: '第',
            afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
            displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

        });
    });
</script>

